package com.reyco1.medusa.events
{
	import flash.events.Event;
	import com.reyco1.medusa.abstract.SmartEventDispatcher;

	public class Dispatcher
	{
		private static var instance:SmartEventDispatcher;
		
		public static function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=true):void
		{
			invalidate();
			instance.addEventListener(type, listener, useCapture, priority, useWeakReference);
		}
		
		public static function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			invalidate();
			instance.removeEventListener(type, listener, useCapture);
		}
		
		public static function removeAllListeners(type:String = null):void
		{
			invalidate();
			instance.removeAllListeners(type);
		}
		
		public static function dispatchEvent(event:Event):Boolean
		{
			invalidate();
			return instance.dispatchEvent(event);
		}
		
		public static function hasEventListener(type:String):Boolean
		{
			invalidate();
			return instance.hasEventListener(type);
		}
		
		public function willTrigger(type:String):Boolean
		{
			invalidate();
			return instance.willTrigger(type);
		}
		
		private static function invalidate():void
		{
			instance = instance == null ? new SmartEventDispatcher() : instance;
		}
	}
}